<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04_员工列表练习</title>
</head>
<body>
    <input type="text" placeholder="请输入员工姓名" id="name">
    <input type="text" placeholder="请输入员工工资" id="salary">
    <input type="text" placeholder="请输入员工岗位" id="job">
    <button onclick="addEmp()">点我添加</button>
    <hr>
    <table border="1">
        <caption>员工列表</caption>
        <tr>
            <th>员工姓名</th>
            <th>员工工资</th>
            <th>员工岗位</th>
        </tr>
        <tr>
            <td>
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>
    <script>
        let arr=[];

        function addEmp(){
            let uName = document.getElementById('name').value;
            let uSalary = document.getElementById('salary').value;
            let uJob = document.getElementById('job').value;
            if(!uName || !uSalary || !uJob){
                alert('请填写完整信息');
                return;
            }
            let trE = document.createElement('tr');
            let nameTd = document.createElement('td');
            nameTd.innerHTML = uName;
            let salaryTd = document.createElement('td');
            salaryTd.innerHTML = uSalary;
            let jobTd = document.createElement('td');
            jobTd.innerHTML = uJob;
            trE.append(nameTd,salaryTd,jobTd);
            let tableE = document.querySelector('table');
            tableE.append(trE);
            document.getElementById('name').value = '';
            document.getElementById('salary').value = '';
            document.getElementById('job').value = '';
            arr.push({
                name:uName,
                salary:uSalary,
                job:uJob
            });
            console.log(arr);
        }
    </script>
</body>
</html>